package com.example.spingbootvue.controller;

import com.example.spingbootvue.entity.Resumemsg;
import com.example.spingbootvue.entity.employeemessage;
import com.example.spingbootvue.mapper.UserResumeMapper;
import com.example.spingbootvue.service.Resume.Insertaccountservice;
import com.example.spingbootvue.service.Resume.resumeservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/userresume")
public class ResumemsgController {

    @Autowired
    UserResumeMapper userResumeMapper;

    @Autowired
    resumeservice resumeservice;

    @Autowired
    Insertaccountservice insertaccountservice;
    @Autowired
    private com.example.spingbootvue.mapper.employeemessageMapper employeemessageMapper;

    //根据登录时用户输入的account在数据库中查询基本信息(name...),映射在简历中
    @GetMapping("/allresumemsg/{account}")
    public List<Resumemsg> selectall(@PathVariable("account") String account){
        return  userResumeMapper.selectresumemsg(account);
    }

    //用户在简历中输入信息(name,age...)点击保存调用更新的接口
    @PutMapping("/updateresumemsg/{account}")
    public int  selectresumemsg(@RequestBody Resumemsg resumemsg,@PathVariable("account") String account){
        return  userResumeMapper.updateuserresumemsg(resumemsg.getName(),resumemsg.getSex(),resumemsg.getAge(),resumemsg.getPhone(),resumemsg.getPosition(),resumemsg.getAddress(),resumemsg.getIntendjob(),account);
    }

     //用户在简历中输入信息(advantage)点击保存调用更新的接口
    @PutMapping("/updateadvantage/{account}")
    public int  updateadvantage(@RequestBody Resumemsg resumemsg,@PathVariable("account") String account){
       return  userResumeMapper.updatebuaccount(resumemsg.getAdvantage(),account);
    }

    //用户在简历中输入信息(experience)点击保存调用更新的接口
    @PutMapping("/updateexperience/{account}")
    public int  updateexperience(@RequestBody Resumemsg resumemsg,@PathVariable("account") String account){
        return  userResumeMapper.updateexperience(resumemsg.getExperiencename(),resumemsg.getExperience(),account);
    }

    //用户在简历中输入信息(match)点击保存调用更新的接口
    @PutMapping("/updatematch/{account}")
    public int  updatematch(@RequestBody Resumemsg resumemsg,@PathVariable("account") String account){
        return  userResumeMapper.updatematch(resumemsg.getMatchname(),resumemsg.getMatchintroduction(),account);
    }

     //注册页面新用户注册在数据库user_biographical_notes表中仅插入account属性值接口
    @PostMapping("/insertaccount/{account}")
    public int insertacocunt(@PathVariable("account") String account){
        return  userResumeMapper.insertaccount(account);
    }

    @GetMapping("/selectemployeemessage")
    public List<employeemessage> selectAll(@RequestParam String account){
        return userResumeMapper.selectemployeemessage(account);
    }

    //用户在简历界面点击按钮插入信息在简历表
    @PostMapping("/judgeaccount")
    public int judegaccount(@RequestBody Resumemsg resumemsg){
        if(insertaccountservice.Insertaccount(resumemsg.getAccount()) == 0){
            return 0;
        }else {
            insertaccountservice.Insertaccount(resumemsg.getAccount());
            return 1;
        }
    }

    // 简历箱中点击查看简历查询对应用户账户的信息
    @GetMapping("/selectbyaccount/{account}")
    public Resumemsg selectbyaccount(@PathVariable("account") String account){
        return  userResumeMapper.querybyaccount(account);
    }

    //简历箱中HR点击发送offer插入文件地址在employeeapply表
    @PutMapping("/updateoffer")
    public int updateoffer(@RequestBody Resumemsg resumemsg){
        if(resumeservice.selectoffer(resumemsg.getOffer(),resumemsg.getId()) == 0){
            return 0;
        }
        else {
            System.out.println("offer"+resumemsg.getOffer());
            resumeservice.selectoffer(resumemsg.getOffer(),resumemsg.getId());
            return 1;
        }
    }

    //用户简历box中查询公司发送的offer
    @GetMapping("/selectoffer")
    public List<employeemessage> selectoffer(@RequestParam String account){
        return userResumeMapper.selectuseroffer(account);
    }

    //HR可以点击忽略屏蔽求职者投的简历
    @PutMapping("/updateByempid")
    public int updateByempid(@RequestBody Resumemsg resumemsg){
        return employeemessageMapper.updateByempid(resumemsg.getId());
    }
}
